mirror of https://github.com/wg-easy/wg-easy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
979 B
37 lines
979 B
import { OneTimeLinkGetSchema } from '#db/repositories/oneTimeLink/types';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const { oneTimeLink } = await getValidatedRouterParams(
|
|
event,
|
|
validateZod(OneTimeLinkGetSchema, event)
|
|
);
|
|
|
|
const otl = await Database.oneTimeLinks.getByOtl(oneTimeLink);
|
|
if (!otl) {
|
|
throw createError({
|
|
statusCode: 404,
|
|
statusMessage: 'Invalid One Time Link',
|
|
});
|
|
}
|
|
|
|
const client = await Database.clients.get(otl.id);
|
|
if (!client) {
|
|
throw createError({
|
|
statusCode: 404,
|
|
statusMessage: 'Invalid One Time Link',
|
|
});
|
|
}
|
|
|
|
const config = await WireGuard.getClientConfiguration({
|
|
clientId: client.id,
|
|
});
|
|
await Database.oneTimeLinks.erase(otl.id);
|
|
|
|
setHeader(
|
|
event,
|
|
'Content-Disposition',
|
|
`attachment; filename="${WireGuard.cleanClientFilename(client.name) || client.id}.conf"`
|
|
);
|
|
setHeader(event, 'Content-Type', 'application/octet-stream');
|
|
return config;
|
|
});
|
|
|